/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package livro.control;

import bibliinfo.FrameMain;
import javax.swing.JOptionPane;
import livro.model.Livro;
import livro.model.LivroDao;

/**
 *
 * @author Ar0n
 */
public class BookFrameDadosAlterarDeletar extends javax.swing.JInternalFrame {

    /**
     * Creates new form BookFrameDadosAlterarExcluir
     */
    public BookFrameDadosAlterarDeletar() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365288027_button_cancel.png"))); // NOI18N
        jButton1.setText("Deletar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(25, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      deletaLivro();      
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton jButton1;
    // End of variables declaration//GEN-END:variables
    //atributos
    private boolean estado;

    //métodos
    public boolean isEstado() {
        return estado;
    }

    public void setEstado(boolean estado) {
        this.estado = estado;
    }    
    
    public void deletaLivro(){
        int i = JOptionPane.showConfirmDialog(FrameMain.bookFrameAltera, 
                "Você realmente deseja excluir este livro e todos os seus exemplares?", "", 0);
          if(i == 0){
              LivroDao dao = new LivroDao();
              Livro livro = new Livro();
              livro.setISBN(FrameMain.bookFrameMain.ISBNSelecionado);
              livro.setAtivo(false);
              dao.delete(livro);
                            
              BookFrameDadosSave save = new BookFrameDadosSave();
              save.limparCampos();
              
              FrameMain.bookFrameAltera.setVisible(false);
              FrameMain.bookFrameAltera.setEstado(false);
              
              FrameMain.bookFrameMain.setVisible(true);
              FrameMain.bookFrameMain.setEstado(true);
              FrameMain.formata(21);
              
          }
    }
}
